import requests
import sys

class ApiClient:
    def __init__(self, base_url):
        self.base_url = base_url

    def get(self, endpoint, params=None, headers=None):
        url = f"{self.base_url}/{endpoint}"
        try:
            response = requests.get(url, params=params, headers=headers)
            response.raise_for_status()  # 检查请求是否成功
            return response.json()  # 假设返回的内容是 JSON 格式
        except requests.RequestException as e:
            print(f"GET请求失败: {e}")
            return None

    def post(self, endpoint, data=None, json=None, headers=None):
        url = f"{self.base_url}/{endpoint}"
        try:
            response = requests.post(url, data=data, json=json, headers=headers)
            response.raise_for_status()  # 检查请求是否成功
            return response.json()  # 假设返回的内容是 JSON 格式
        except requests.RequestException as e:
            print(f"POST请求失败: {e}")
            return None

    def background_login(self, account, password, authCode):

        get_response = self.post("moyin-admin-service/sys/login",
                                 data={"account": account, "password": password,
                                       "authCode": authCode})
        return get_response


if __name__ == "__main__":
    if len(sys.argv) < 4:
        print("请提供账户参数")
        sys.exit(1)

    account = sys.argv[1]
    password = sys.argv[2]
    authCode = sys.argv[3]

    base_url = "https://bltest.ah-suuwaa.com/api"  # 替换为你的 API 基础 URL
    client = ApiClient(base_url)

    # # 发送 GET 请求
    # get_response = client.get("some/endpoint", params={"key": "value"})
    # print(get_response)

    # # 发送 POST 请求
    # post_response = client.post("some/endpoint", json={"key": "value"})
    # print(post_response)

    # get_response = client.post("moyin-admin-service/sys/login",
    #                            data={"account": "admin", "password": "e10adc3949ba59abbe56e057f20f883e",
    #                                  "authCode": "111111"})
    # print(get_response)

    print(client.background_login(account, password, authCode))
